<template>
  <a-dialog-keep :visible="open" title="批量发送短信" width="800px">
    <el-form label-position="left" class="demo-table-expand" label-width="100px" size="mini">
      <el-row>
        <el-col :span="24">
          <el-form-item label="接收人员" prop="cate">
            {{ userNames }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="短信内容">
            <el-input v-model="formData.content" type="textarea" placeholder="请输入短信内容" :style="{ width: '100%' }"
              :rows="5">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="同时发送">
            <el-checkbox-group v-model="formData.syncSend">
              <el-checkbox label="语音电话"></el-checkbox>
              <el-checkbox label="传真"></el-checkbox>
              <el-checkbox label="邮件"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel" size="mini">关闭</el-button>
      <el-button type="primary" @click="handleSend" size="mini">确认发送</el-button>
    </div>
  </a-dialog-keep>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin';
import RadioRecord from './RadioRecord.vue';
import * as DispatchApi from '@/api/response/dispatch'
export default {
  name: 'BatchSmsDialog',
  mixins: [dialogMixin],
  components: { RadioRecord },
  data() {
    return {
      formData: {
        contentType: 2,
        syncSend: [],
        users: []
      },
      userNames: '',
    }
  },
  methods: {
    show(users) {
      let userNames = [];
      users.forEach(u => {
        userNames.push(u.nickName);
      })
      this.userNames = userNames.join(',')
      this.users = users;
      this.open = true;
    },
    cancel() {
      this.open = false;
    },
    handleSend() {
      this.$modal.loading("正在批量发送...");
      let phones = [];
      this.users.forEach(u => {
        if (u.phonenumber != null && u.phonenumber != '') {
          phones.push(u.phonenumber);
        }
      })
      DispatchApi.sendBatchSms({ phones: phones, content: this.formData.content }).then(res => {
        this.$modal.closeLoading();
        this.open = false;
        this.$modal.msgSuccess('已批量完成发送')
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>